<template>
	<view>
		<!-- #ifdef MP-WEIXIN -->
		<view style="height: 55rpx"></view>
		<!-- #endif -->
		<view class="title">首页</view>
		<view class="icon">
			<view class="row" @click="traningFun(0)">
				<image :src="`${setting.sImgUrl}/index/icon1.png`" />
				<view>私教课</view>
			</view>
			<view class="row" @click="traningFun(1)">
				<image :src="`${setting.sImgUrl}/index/icon2.png`" />
				<view>线上体系课</view>
			</view>
			<navigator class="row" hover-class="none" url="/pages/student/play/play">
				<image :src="`${setting.sImgUrl}/index/icon3.png`" />
				<view>计分工具</view>
			</navigator>
			<navigator class="row" hover-class="none" url="/pages/student/evaluation/evaluation">
				<image :src="`${setting.sImgUrl}/index/icon4.png`" />
				<view>我的测评</view>
			</navigator>
			<view class="row" @click="traningFun(2)">
				<image :src="`${setting.sImgUrl}/index/icon5.png`" />
				<view>1对1答疑</view>
			</view>
		</view>
		<!-- 我的教练 -->
		<view class="coach">
			<view class="top">
				<view class="left">我的教练</view>
				<navigator class="more" hover-class="none" url="/pages/student/training/train">更多</navigator>
			</view>
			<view class="entry" v-if="coach.length">
				<navigator
					v-for="(v, k) in coach"
					:key="k"
					:url="`/pages/student/training/coach-detail?id=${v.instructorId}`"
					hover-class="none"
				>
					<view class="row">
						<image :src="setting.oss_pub_domain + v.instructorAvatar" />
						<view>
							<view class="name">{{ v.instructorName }}</view>
							<view class="dsc">
								<text>训练课程 {{ v.courseNum }}</text>
								<view class="line"></view>
								<text>已学课程 {{ v.studyNum }}</text>
							</view>
						</view>
					</view>
				</navigator>
			</view>
			<view class="empty" v-else>
				<view>
					<image :src="`${setting.sImgUrl}/index/pc@2x.png`" />
				</view>
				<view>暂未绑定教练</view>
			</view>
		</view>
		<!-- #ifndef MP-WEIXIN -->
		<navigator
			:url="setting.instructor_banner_dictExtF"
			v-if="setting.instructor_banner"
			class="home-banner"
			hover-class="none"
		>
			<image :src="setting.oss_pub_domain + setting.instructor_banner"></image>
		</navigator>
		<!-- #endif -->
		<!-- #ifdef MP-WEIXIN -->
		<navigator
			:url="setting.mp_banner_dictExtF"
			v-if="setting.mp_banner"
			class="home-banner"
			hover-class="none"
		>
			<image :src="setting.oss_pub_domain + setting.mp_banner"></image>
		</navigator>
		<!-- #endif -->
		<!-- 即将训练 -->
		<view class="train">
			<view class="top">
				<view class="left"><image :src="`${setting.sImgUrl}/index/text@2x.png`" /></view>
				<navigator class="more" hover-class="none" url="/pages/student/course/entry">更多</navigator>
			</view>
			<view v-if="course && course.length" class="entry">
				<view class="row" v-for="(item, index) in course" :key="index" @click="viewCourse(item)">
					<view class="part">
						<view class="left u-line-1">
							<image :src="`${setting.sImgUrl}/index/icon@2x.png`" />
							<text class="text-w u-line-1">{{ item.name }}</text>
						</view>
						<view class="time flex_sh">{{ item.beginTime }}</view>
					</view>
					<view v-for="(row, idx) in item.relQuestionSchemeList" :key="idx" class="part2 u-line-1">
						<view>
							<view class="text-w">问题{{ idx + 1 }}:{{ row.name }}</view>
							<view class="uni-mt-16 u-line-1">{{ row.descriptionTagName }}</view>
						</view>
					</view>
				</view>
			</view>
			<z-no-data v-else></z-no-data>
		</view>
		<!-- 近期完成训练 -->
		<view class="train trains">
			<view class="top">
				<view class="left">近期完成训练</view>
				<navigator class="more" hover-class="none" url="/pages/student/course/entry">更多</navigator>
			</view>
			<view v-if="finishCourse && finishCourse.length" class="entry">
				<view class="row" v-for="(item, index) in finishCourse" :key="index" @click="viewCourse(item)">
					<view class="part">
						<view class="left">
							<image :src="`${setting.sImgUrl}/index/icon@2x.png`" />
							<text class="text-w u-line-1">{{ item.name }}</text>
						</view>
						<view class="time flex_sh">{{ item.beginTime }}</view>
					</view>
					<view v-for="(row, idx) in item.relQuestionSchemeList" :key="idx" class="part2 u-line-1">
						<view>
							<view class="text-w">问题{{ idx + 1 }}:{{ row.name }}</view>
							<view class="uni-mt-16 u-line-1">{{ row.descriptionTagName }}</view>
						</view>
					</view>
				</view>
			</view>
			<z-no-data v-else></z-no-data>
		</view>
		<!-- 精品体系课 -->
		<view class="course">
			<view class="top">
				<view class="left">精品体系课</view>
				<navigator
					class="more"
					hover-class="none"
					url="/pages/tabbar-page/tabbar-1?type=0"
					open-type="reLaunch"
				>
					更多
				</navigator>
			</view>
			<view v-if="openCourse && openCourse.length" class="entry">
				<navigator
					v-for="(v, k) in openCourse"
					:key="k"
					:url="`/pages/student/course/open?id=${v.id}`"
					hover-class="none"
				>
					<view class="row">
						<image :src="setting.oss_pub_domain + v.coverImage" />
						<view class="right">
							<view>{{ v.name }}</view>
							<view class="second">
								<view>课程: {{ v.duration }}</view>
								<view class="line"></view>
								<view>
									<text>兑换:</text>
									<text>{{ v.exchange }}</text>
								</view>
							</view>
							<view class="bottom">
								<view class="left">
									<image :src="setting.oss_pub_domain + v.instructorAvatar" />
									<text>{{ v.instructorName }}</text>
								</view>
								<view class="other">
									<image :src="`${setting.sImgUrl}/index/icon_drop-down@2x.png`" />
									<text>{{ v.praiseNum }}</text>
								</view>
							</view>
						</view>
					</view>
				</navigator>
			</view>
			<z-no-data v-else></z-no-data>
		</view>
		<!-- 近期赛事 -->
		<view class="game">
			<view class="top">
				<view class="left">近期赛事</view>
				<view class="more" @click="moreGame">更多</view>
			</view>
			<view v-if="game && game.length" class="entry">
				<navigator
					class="row"
					v-for="(v, k) in game"
					:key="k"
					hover-class="none"
					:url="'/pages/student/find/articles-detail?id=' + v.id"
				>
					<view class="text">{{ v.title }}</view>
					<view class="dsc">{{ v.content }}</view>
					<image class="one" :src="setting.oss_pub_domain + v.coverImage" v-if="v.img.length == 1" />
					<view class="three" v-else>
						<image :src="setting.oss_pub_domain + val" v-for="(val, key) in v.img" :key="key" />
					</view>
				</navigator>
			</view>
			<z-no-data v-else></z-no-data>
		</view>
	</view>
</template>

<script>
import { getGame, getCourse, getFinishCourse, getCoach, getOpenCourse, courseOnlyStuDetail } from '@/api/student';
export default {
	data() {
		return {
			coach: [],
			game: [],
			course: [],
			finishCourse: [],
			openCourse: [],
			nav: '',
			height: ''
		};
	},
	methods: {
		// 近期赛事
		async getGames() {
			const { rows } = await getGame({ pageSize: 3 });
			console.log(rows);
			this.game = rows.map((item) => {
				item.img = item.coverImage.split(',');
				return item;
			});
		},
		// 即将训练课程
		async getCourses() {
			this.course = await getCourse();
		},
		// 近期完成的课程
		async getFinishCourses() {
			this.finishCourse = await getFinishCourse();
		},
		// 我的教练
		async getCoachs() {
			const { rows } = await getCoach({ pageSize: 5 });
			this.coach = rows;
		},
		// 体系课
		async getOpenCourses() {
			const { rows } = await getOpenCourse();
			this.openCourse = rows;
		},
		showFun() {
			this.getGames();
			this.getCourses();
			this.getCoachs();
			this.getOpenCourses();
			this.getFinishCourses();
		},
		viewCourse(item) {
			courseOnlyStuDetail(item.id).then((res) => {
				res.result = JSON.parse(res.result);
				uni.setStorageSync('edit-course', res);
				uni.navigateTo({
					url: '/pages/course/details/details'
				});
			});
		},
		moreGame() {
			uni.setStorageSync('find-type', 1);
			uni.switchTab({
				url: '/pages/tabbar-page/tabbar-1'
			});
		},
		traningFun(e) {
			uni.setStorageSync('entry-type', e);
			uni.switchTab({
				url: '/pages/tabbar-page/tabbar-3'
			});
		}
	}
};
</script>

<style lang="scss">
@import './index.scss';
</style>
